#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import os.path
from filecmp import dircmp
import shutil

path1 = os.path.normpath(sys.argv[1])
path2 = os.path.normpath(sys.argv[2])
ignore = ['.git']

diffexist = False

def find_diff_files(dcmp):
    global diffexist
    for name in dcmp.diff_files:
        diffexist = True
        print("%s    --  found in [%s] and [%s]" % (name, dcmp.left, dcmp.right))
    for name in dcmp.left_only:
        diffexist = True
        print("%s    --  found in [%s] left only" % (name, dcmp.left))
    for sd in dcmp.subdirs.itervalues():
        find_diff_files(sd)

def copy_diff_files(dcmp):
    for name in dcmp.diff_files:
        src = os.path.join(dcmp.left, name)
        dst = os.path.join(dcmp.right, name)
        print("%s    ## was copied from [%s] to [%s]" % (name, dcmp.left, dcmp.right))
        shutil.copy(src, dst)
    for name in dcmp.left_only:
        src = os.path.join(dcmp.left, name)
        dst = os.path.join(dcmp.right, name)
        print("%s    ## was copied from [%s] to [%s]" % (name, dcmp.left, dcmp.right))
        shutil.copy(src, dst)
    for sd in dcmp.subdirs.itervalues():
        copy_diff_files(sd)

dcmp = dircmp(path1, path2, ignore=ignore)

find_diff_files(dcmp)
# dcmp.report_full_closure()

if diffexist:
    print '--------------------------------------------------------------'
    copydiffile = raw_input("Need copy these files: [y/n]")
    if copydiffile == "y" or copydiffile == "yes":
        copy_diff_files(dcmp) 
